package com.jxs.android.weiget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.View;
import android.widget.LinearLayout.LayoutParams;
import android.widget.PopupWindow;

@SuppressLint("ViewConstructor")
public class FilterViewWinPop extends PopupWindow {

	/** 下拉视图的宽度 */
	private int mViewWidth;
	/** 下拉视图的高度 */
	private int mViewHeight;

	private FilterViewCreatedListener createdListener;

	public FilterViewWinPop(Context context, View view) {
		super(context);
		loadViews(view);
	}

	/**
	 * @Description: TODO 加载布局文件
	 * @param
	 * @return void
	 * @throws
	 */
	private void loadViews(View v) {
		// 布局加载器加载布局文件
		// 计算view宽高
		onMeasured(v);

		// 必须设置
		setWidth(LayoutParams.FILL_PARENT);
		setHeight(LayoutParams.WRAP_CONTENT);
		setContentView(v);
		setFocusable(true);

		// 设置布局创建监听器，以便在实例化布局控件对象
		if (createdListener != null) {
			createdListener.onViewCreated(v);
		}
	}

	/**
	 * @Description: TODO 计算View长宽
	 * @param @param v
	 */
	private void onMeasured(View v) {
		int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
		int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
		v.measure(w, h);
		mViewWidth = v.getMeasuredWidth();
		mViewHeight = v.getMeasuredHeight();
	}

	public int getmViewWidth() {
		return mViewWidth;
	}

	public void setmViewWidth(int mViewWidth) {
		this.mViewWidth = mViewWidth;
	}

	public int getmViewHeight() {
		return mViewHeight;
	}

	public void setmViewHeight(int mViewHeight) {
		this.mViewHeight = mViewHeight;
	}

	public void setFilterViewCreatedListener(FilterViewCreatedListener createdListener) {
		this.createdListener = createdListener;
	}

}
